{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.2.0+cu92'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import pandas_profiling as ppf\n",
    "# from tensorboardX import SummaryWriter\n",
    "from sklearn.model_selection import train_test_split\n",
    "# writer=SummaryWriter(logdir='./logistic')\n",
    "torch.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## logistic回归介绍"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "logistic回归是一种广义线性回归（generalized linear model），与多重线性回归分析有很多相同之处。它们的模型形式基本上相同，都具有 wx + b，其中w和b是待求参数，其区别在于他们的因变量不同，多重线性回归直接将wx+b作为因变量，即y =wx+b,而logistic回归则通过函数L将wx+b对应一个隐状态p，p =L(wx+b),然后根据p 与1-p的大小决定因变量的值。如果L是logistic函数，就是logistic回归，如果L是多项式函数就是多项式回归。\n",
    "\n",
    "说的更通俗一点，就是logistic回归会在线性回归后再加一层logistic函数的调用。\n",
    "\n",
    "logistic回归主要是进行二分类预测，我们在激活函数时候讲到过 Sigmod函数，Sigmod函数是最常见的logistic函数，因为Sigmod函数的输出的是是对于0~1之间的概率值，当概率大于0.5预测为1，小于0.5预测为0。\n",
    "\n",
    "以下为僵尸企业分类的逻辑回归实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "encoded_all_data=pd.read_csv(r'./data/created_data/encoded_all_data.csv').reset_index(drop=True).set_index('ID')\n",
    "init_x=encoded_all_data.dropna(subset=['flag']).drop(['flag'],axis=1)\n",
    "init_y=encoded_all_data.dropna(subset=['flag'])['flag']\n",
    "# encoded_all_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>zhaiquanrongzi_chengben</th>\n",
       "      <th>zhaiquanrongzi_edu</th>\n",
       "      <th>neiburongzi_and_maoyirongzi_chengben</th>\n",
       "      <th>neiburongzi_and_maoyirongzi_edu</th>\n",
       "      <th>jinglirun</th>\n",
       "      <th>lirunzonge</th>\n",
       "      <th>suoyouzhe_quanyiheji</th>\n",
       "      <th>nashui_zonge</th>\n",
       "      <th>guquanrognzi_chengben</th>\n",
       "      <th>guquanrognzi_edu</th>\n",
       "      <th>yingye_zongshouru</th>\n",
       "      <th>fuzhai_zonge</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5992282.0</th>\n",
       "      <td>-0.140242</td>\n",
       "      <td>-0.139879</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>-0.114495</td>\n",
       "      <td>-0.612358</td>\n",
       "      <td>0.269269</td>\n",
       "      <td>-0.340802</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>-0.693239</td>\n",
       "      <td>-0.705462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5982045.0</th>\n",
       "      <td>1.966176</td>\n",
       "      <td>1.966437</td>\n",
       "      <td>0.052762</td>\n",
       "      <td>-0.216089</td>\n",
       "      <td>1.596196</td>\n",
       "      <td>1.148906</td>\n",
       "      <td>0.533604</td>\n",
       "      <td>3.938261</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>2.712321</td>\n",
       "      <td>1.191353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>895831.0</th>\n",
       "      <td>0.786722</td>\n",
       "      <td>0.787260</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>-0.716335</td>\n",
       "      <td>0.826067</td>\n",
       "      <td>0.255958</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>0.547068</td>\n",
       "      <td>0.546235</td>\n",
       "      <td>0.432168</td>\n",
       "      <td>0.348116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5985243.0</th>\n",
       "      <td>-0.322979</td>\n",
       "      <td>-0.322662</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.214615</td>\n",
       "      <td>-0.155016</td>\n",
       "      <td>-0.640345</td>\n",
       "      <td>0.219881</td>\n",
       "      <td>-0.380627</td>\n",
       "      <td>-0.283383</td>\n",
       "      <td>-0.283391</td>\n",
       "      <td>-0.729194</td>\n",
       "      <td>-0.748672</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5983883.0</th>\n",
       "      <td>-0.042745</td>\n",
       "      <td>-0.042454</td>\n",
       "      <td>-0.218925</td>\n",
       "      <td>-0.219351</td>\n",
       "      <td>-0.306733</td>\n",
       "      <td>-0.338618</td>\n",
       "      <td>0.228194</td>\n",
       "      <td>-0.386355</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.190409</td>\n",
       "      <td>-0.401226</td>\n",
       "      <td>-0.508057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5984896.0</th>\n",
       "      <td>1.196130</td>\n",
       "      <td>1.196813</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>1.549562</td>\n",
       "      <td>0.811447</td>\n",
       "      <td>0.434845</td>\n",
       "      <td>1.086850</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>0.414652</td>\n",
       "      <td>0.372022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5996407.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>0.036678</td>\n",
       "      <td>0.037324</td>\n",
       "      <td>0.111706</td>\n",
       "      <td>-0.215827</td>\n",
       "      <td>0.511119</td>\n",
       "      <td>-0.046966</td>\n",
       "      <td>-0.062900</td>\n",
       "      <td>-0.062541</td>\n",
       "      <td>-0.365487</td>\n",
       "      <td>-0.666507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5994688.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.132856</td>\n",
       "      <td>-0.133514</td>\n",
       "      <td>0.123423</td>\n",
       "      <td>-0.215391</td>\n",
       "      <td>-0.447947</td>\n",
       "      <td>0.100624</td>\n",
       "      <td>0.266530</td>\n",
       "      <td>0.267311</td>\n",
       "      <td>-0.224783</td>\n",
       "      <td>0.548445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5985391.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.289779</td>\n",
       "      <td>-0.290066</td>\n",
       "      <td>-0.171231</td>\n",
       "      <td>-0.619866</td>\n",
       "      <td>0.641145</td>\n",
       "      <td>-0.394550</td>\n",
       "      <td>-0.229778</td>\n",
       "      <td>-0.229855</td>\n",
       "      <td>-0.713523</td>\n",
       "      <td>-0.590810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>584259.0</th>\n",
       "      <td>1.838419</td>\n",
       "      <td>1.839643</td>\n",
       "      <td>0.489167</td>\n",
       "      <td>0.485606</td>\n",
       "      <td>-1.149829</td>\n",
       "      <td>2.442112</td>\n",
       "      <td>0.797075</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>2.046365</td>\n",
       "      <td>2.044501</td>\n",
       "      <td>1.488990</td>\n",
       "      <td>0.891506</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>24953 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           zhaiquanrongzi_chengben  zhaiquanrongzi_edu  \\\n",
       "ID                                                       \n",
       "5992282.0                -0.140242           -0.139879   \n",
       "5982045.0                 1.966176            1.966437   \n",
       "895831.0                  0.786722            0.787260   \n",
       "5985243.0                -0.322979           -0.322662   \n",
       "5983883.0                -0.042745           -0.042454   \n",
       "...                            ...                 ...   \n",
       "5984896.0                 1.196130            1.196813   \n",
       "5996407.0                -0.376463           -0.376167   \n",
       "5994688.0                -0.376463           -0.376167   \n",
       "5985391.0                -0.376463           -0.376167   \n",
       "584259.0                  1.838419            1.839643   \n",
       "\n",
       "           neiburongzi_and_maoyirongzi_chengben  \\\n",
       "ID                                                \n",
       "5992282.0                             -0.325154   \n",
       "5982045.0                              0.052762   \n",
       "895831.0                              -0.325154   \n",
       "5985243.0                             -0.325154   \n",
       "5983883.0                             -0.218925   \n",
       "...                                         ...   \n",
       "5984896.0                             -0.325154   \n",
       "5996407.0                              0.036678   \n",
       "5994688.0                             -0.132856   \n",
       "5985391.0                             -0.289779   \n",
       "584259.0                               0.489167   \n",
       "\n",
       "           neiburongzi_and_maoyirongzi_edu  jinglirun  lirunzonge  \\\n",
       "ID                                                                  \n",
       "5992282.0                        -0.325293  -0.114495   -0.612358   \n",
       "5982045.0                        -0.216089   1.596196    1.148906   \n",
       "895831.0                         -0.325293  -0.716335    0.826067   \n",
       "5985243.0                        -0.214615  -0.155016   -0.640345   \n",
       "5983883.0                        -0.219351  -0.306733   -0.338618   \n",
       "...                                    ...        ...         ...   \n",
       "5984896.0                        -0.325293   1.549562    0.811447   \n",
       "5996407.0                         0.037324   0.111706   -0.215827   \n",
       "5994688.0                        -0.133514   0.123423   -0.215391   \n",
       "5985391.0                        -0.290066  -0.171231   -0.619866   \n",
       "584259.0                          0.485606  -1.149829    2.442112   \n",
       "\n",
       "           suoyouzhe_quanyiheji  nashui_zonge  guquanrognzi_chengben  \\\n",
       "ID                                                                     \n",
       "5992282.0              0.269269     -0.340802              -0.285456   \n",
       "5982045.0              0.533604      3.938261              -0.285456   \n",
       "895831.0               0.255958     -0.463019               0.547068   \n",
       "5985243.0              0.219881     -0.380627              -0.283383   \n",
       "5983883.0              0.228194     -0.386355              -0.285456   \n",
       "...                         ...           ...                    ...   \n",
       "5984896.0              0.434845      1.086850              -0.285456   \n",
       "5996407.0              0.511119     -0.046966              -0.062900   \n",
       "5994688.0             -0.447947      0.100624               0.266530   \n",
       "5985391.0              0.641145     -0.394550              -0.229778   \n",
       "584259.0               0.797075     -0.463019               2.046365   \n",
       "\n",
       "           guquanrognzi_edu  yingye_zongshouru  fuzhai_zonge  \n",
       "ID                                                            \n",
       "5992282.0         -0.285470          -0.693239     -0.705462  \n",
       "5982045.0         -0.285470           2.712321      1.191353  \n",
       "895831.0           0.546235           0.432168      0.348116  \n",
       "5985243.0         -0.283391          -0.729194     -0.748672  \n",
       "5983883.0         -0.190409          -0.401226     -0.508057  \n",
       "...                     ...                ...           ...  \n",
       "5984896.0         -0.285470           0.414652      0.372022  \n",
       "5996407.0         -0.062541          -0.365487     -0.666507  \n",
       "5994688.0          0.267311          -0.224783      0.548445  \n",
       "5985391.0         -0.229855          -0.713523     -0.590810  \n",
       "584259.0           2.044501           1.488990      0.891506  \n",
       "\n",
       "[24953 rows x 12 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "ID\n",
       "5992282.0    0.0\n",
       "5982045.0    0.0\n",
       "895831.0     1.0\n",
       "5985243.0    0.0\n",
       "5983883.0    0.0\n",
       "            ... \n",
       "5984896.0    0.0\n",
       "5996407.0    0.0\n",
       "5994688.0    0.0\n",
       "5985391.0    0.0\n",
       "584259.0     1.0\n",
       "Name: flag, Length: 24953, dtype: float64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>zhaiquanrongzi_chengben</th>\n",
       "      <th>zhaiquanrongzi_edu</th>\n",
       "      <th>neiburongzi_and_maoyirongzi_chengben</th>\n",
       "      <th>neiburongzi_and_maoyirongzi_edu</th>\n",
       "      <th>jinglirun</th>\n",
       "      <th>lirunzonge</th>\n",
       "      <th>suoyouzhe_quanyiheji</th>\n",
       "      <th>nashui_zonge</th>\n",
       "      <th>guquanrognzi_chengben</th>\n",
       "      <th>guquanrognzi_edu</th>\n",
       "      <th>yingye_zongshouru</th>\n",
       "      <th>fuzhai_zonge</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5997249.0</th>\n",
       "      <td>-0.034880</td>\n",
       "      <td>-0.034590</td>\n",
       "      <td>0.016378</td>\n",
       "      <td>0.015317</td>\n",
       "      <td>0.578049</td>\n",
       "      <td>-0.139479</td>\n",
       "      <td>-0.210866</td>\n",
       "      <td>0.160015</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>-0.058149</td>\n",
       "      <td>-0.227895</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999913.0</th>\n",
       "      <td>-0.331225</td>\n",
       "      <td>-0.330930</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>-0.158613</td>\n",
       "      <td>-0.652001</td>\n",
       "      <td>0.209697</td>\n",
       "      <td>-0.410833</td>\n",
       "      <td>-0.279166</td>\n",
       "      <td>-0.279187</td>\n",
       "      <td>-0.744123</td>\n",
       "      <td>-0.764257</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2088184.0</th>\n",
       "      <td>-0.220277</td>\n",
       "      <td>-0.219916</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>-0.300022</td>\n",
       "      <td>-0.528869</td>\n",
       "      <td>0.043826</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.112608</td>\n",
       "      <td>-0.112513</td>\n",
       "      <td>-0.558673</td>\n",
       "      <td>-0.436801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5980104.0</th>\n",
       "      <td>-0.358507</td>\n",
       "      <td>-0.358211</td>\n",
       "      <td>-0.322216</td>\n",
       "      <td>-0.322362</td>\n",
       "      <td>-0.150429</td>\n",
       "      <td>-0.640118</td>\n",
       "      <td>0.248568</td>\n",
       "      <td>-0.396280</td>\n",
       "      <td>-0.259479</td>\n",
       "      <td>-0.259422</td>\n",
       "      <td>-0.715331</td>\n",
       "      <td>-0.787033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3306270.0</th>\n",
       "      <td>-0.186045</td>\n",
       "      <td>-0.185752</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>-0.454422</td>\n",
       "      <td>-0.209520</td>\n",
       "      <td>-0.554775</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>-0.190211</td>\n",
       "      <td>0.273736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2668569.0</th>\n",
       "      <td>0.432479</td>\n",
       "      <td>0.432943</td>\n",
       "      <td>-0.008793</td>\n",
       "      <td>-0.009786</td>\n",
       "      <td>-0.815304</td>\n",
       "      <td>0.637272</td>\n",
       "      <td>-0.937810</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.012347</td>\n",
       "      <td>-0.012578</td>\n",
       "      <td>0.678724</td>\n",
       "      <td>1.644362</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2735249.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.054913</td>\n",
       "      <td>-0.054466</td>\n",
       "      <td>-0.943644</td>\n",
       "      <td>0.502727</td>\n",
       "      <td>-0.324949</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>1.385249</td>\n",
       "      <td>1.388950</td>\n",
       "      <td>0.971290</td>\n",
       "      <td>0.615503</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5978857.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>-0.110419</td>\n",
       "      <td>-0.363604</td>\n",
       "      <td>0.194189</td>\n",
       "      <td>-0.268188</td>\n",
       "      <td>0.223692</td>\n",
       "      <td>0.223322</td>\n",
       "      <td>-0.558967</td>\n",
       "      <td>-0.549562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1604747.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.306316</td>\n",
       "      <td>-0.306506</td>\n",
       "      <td>-0.317953</td>\n",
       "      <td>-0.147783</td>\n",
       "      <td>-0.280946</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>0.227534</td>\n",
       "      <td>0.227113</td>\n",
       "      <td>-0.512628</td>\n",
       "      <td>-0.017216</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5985633.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.239306</td>\n",
       "      <td>-0.239805</td>\n",
       "      <td>-0.024212</td>\n",
       "      <td>-0.255729</td>\n",
       "      <td>0.304445</td>\n",
       "      <td>-0.139081</td>\n",
       "      <td>0.326168</td>\n",
       "      <td>0.325646</td>\n",
       "      <td>-0.336126</td>\n",
       "      <td>-0.612859</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10695 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           zhaiquanrongzi_chengben  zhaiquanrongzi_edu  \\\n",
       "ID                                                       \n",
       "5997249.0                -0.034880           -0.034590   \n",
       "5999913.0                -0.331225           -0.330930   \n",
       "2088184.0                -0.220277           -0.219916   \n",
       "5980104.0                -0.358507           -0.358211   \n",
       "3306270.0                -0.186045           -0.185752   \n",
       "...                            ...                 ...   \n",
       "2668569.0                 0.432479            0.432943   \n",
       "2735249.0                -0.376463           -0.376167   \n",
       "5978857.0                -0.376463           -0.376167   \n",
       "1604747.0                -0.376463           -0.376167   \n",
       "5985633.0                -0.376463           -0.376167   \n",
       "\n",
       "           neiburongzi_and_maoyirongzi_chengben  \\\n",
       "ID                                                \n",
       "5997249.0                              0.016378   \n",
       "5999913.0                             -0.325154   \n",
       "2088184.0                             -0.325154   \n",
       "5980104.0                             -0.322216   \n",
       "3306270.0                             -0.325154   \n",
       "...                                         ...   \n",
       "2668569.0                             -0.008793   \n",
       "2735249.0                             -0.054913   \n",
       "5978857.0                             -0.325154   \n",
       "1604747.0                             -0.306316   \n",
       "5985633.0                             -0.239306   \n",
       "\n",
       "           neiburongzi_and_maoyirongzi_edu  jinglirun  lirunzonge  \\\n",
       "ID                                                                  \n",
       "5997249.0                         0.015317   0.578049   -0.139479   \n",
       "5999913.0                        -0.325293  -0.158613   -0.652001   \n",
       "2088184.0                        -0.325293  -0.300022   -0.528869   \n",
       "5980104.0                        -0.322362  -0.150429   -0.640118   \n",
       "3306270.0                        -0.325293  -0.454422   -0.209520   \n",
       "...                                    ...        ...         ...   \n",
       "2668569.0                        -0.009786  -0.815304    0.637272   \n",
       "2735249.0                        -0.054466  -0.943644    0.502727   \n",
       "5978857.0                        -0.325293  -0.110419   -0.363604   \n",
       "1604747.0                        -0.306506  -0.317953   -0.147783   \n",
       "5985633.0                        -0.239805  -0.024212   -0.255729   \n",
       "\n",
       "           suoyouzhe_quanyiheji  nashui_zonge  guquanrognzi_chengben  \\\n",
       "ID                                                                     \n",
       "5997249.0             -0.210866      0.160015              -0.285456   \n",
       "5999913.0              0.209697     -0.410833              -0.279166   \n",
       "2088184.0              0.043826     -0.463019              -0.112608   \n",
       "5980104.0              0.248568     -0.396280              -0.259479   \n",
       "3306270.0             -0.554775     -0.463019              -0.285456   \n",
       "...                         ...           ...                    ...   \n",
       "2668569.0             -0.937810     -0.463019              -0.012347   \n",
       "2735249.0             -0.324949     -0.463019               1.385249   \n",
       "5978857.0              0.194189     -0.268188               0.223692   \n",
       "1604747.0             -0.280946     -0.463019               0.227534   \n",
       "5985633.0              0.304445     -0.139081               0.326168   \n",
       "\n",
       "           guquanrognzi_edu  yingye_zongshouru  fuzhai_zonge  \n",
       "ID                                                            \n",
       "5997249.0         -0.285470          -0.058149     -0.227895  \n",
       "5999913.0         -0.279187          -0.744123     -0.764257  \n",
       "2088184.0         -0.112513          -0.558673     -0.436801  \n",
       "5980104.0         -0.259422          -0.715331     -0.787033  \n",
       "3306270.0         -0.285470          -0.190211      0.273736  \n",
       "...                     ...                ...           ...  \n",
       "2668569.0         -0.012578           0.678724      1.644362  \n",
       "2735249.0          1.388950           0.971290      0.615503  \n",
       "5978857.0          0.223322          -0.558967     -0.549562  \n",
       "1604747.0          0.227113          -0.512628     -0.017216  \n",
       "5985633.0          0.325646          -0.336126     -0.612859  \n",
       "\n",
       "[10695 rows x 12 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "ID\n",
       "5997249.0    0.0\n",
       "5999913.0    0.0\n",
       "2088184.0    1.0\n",
       "5980104.0    0.0\n",
       "3306270.0    1.0\n",
       "            ... \n",
       "2668569.0    1.0\n",
       "2735249.0    1.0\n",
       "5978857.0    0.0\n",
       "1604747.0    1.0\n",
       "5985633.0    0.0\n",
       "Name: flag, Length: 10695, dtype: float64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "zhaiquanrongzi_chengben                 float64\n",
       "zhaiquanrongzi_edu                      float64\n",
       "neiburongzi_and_maoyirongzi_chengben    float64\n",
       "neiburongzi_and_maoyirongzi_edu         float64\n",
       "jinglirun                               float64\n",
       "lirunzonge                              float64\n",
       "suoyouzhe_quanyiheji                    float64\n",
       "nashui_zonge                            float64\n",
       "guquanrognzi_chengben                   float64\n",
       "guquanrognzi_edu                        float64\n",
       "yingye_zongshouru                       float64\n",
       "fuzhai_zonge                            float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_X,val_X, train_y, val_y = train_test_split(init_x,init_y,test_size=0.30, random_state=0)\n",
    "display(train_X,train_y)\n",
    "display(val_X,val_y)\n",
    "val_X.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### logistic regression model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "class LR(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(LR,self).__init__()\n",
    "        self.fc=nn.Linear(12,2) # 由于16个维度已经固定了，所以这里写16\n",
    "    def forward(self,x):\n",
    "        x=self.fc(x)\n",
    "        out=torch.sigmoid(x)\n",
    "        return out\n",
    "\n",
    "\n",
    "def test(pred,lab):\n",
    "    t=pred.max(-1)[1]==lab\n",
    "    return torch.mean(t.float())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_default_device():\n",
    "    \"\"\"Pick GPU if available, else CPU\"\"\"\n",
    "    if torch.cuda.is_available():\n",
    "        return torch.device('cuda')\n",
    "    else:\n",
    "        return torch.device('cpu')\n",
    "\n",
    "def to_device(data, device):\n",
    "    \"\"\"Move tensor(s) to chosen device\"\"\"\n",
    "    if isinstance(data, (list,tuple)):\n",
    "        return [to_device(x, device) for x in data]\n",
    "    return data.to(device, non_blocking=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "device(type='cuda')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "device = get_default_device()\n",
    "device"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 网络模型实例化\n",
    "net=LR()\n",
    "to_device(net, device)\n",
    "# 使用CrossEntropyLoss损失\n",
    "criterion=nn.CrossEntropyLoss() # BCEloss待测\n",
    "# 优化器\n",
    "optm=torch.optim.Adam(net.parameters(),lr=0.1) \n",
    "# 训练1500次\n",
    "epochs=1000"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### train model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch:200,Loss:0.3296,Accuracy：0.9820\n",
      "Epoch:400,Loss:0.3296,Accuracy：0.9820\n",
      "Epoch:600,Loss:0.3296,Accuracy：0.9820\n",
      "Epoch:800,Loss:0.3296,Accuracy：0.9820\n",
      "Epoch:1000,Loss:0.3295,Accuracy：0.9820\n",
      "Epoch:1200,Loss:0.3295,Accuracy：0.9820\n",
      "Epoch:1400,Loss:0.3295,Accuracy：0.9820\n",
      "Epoch:1600,Loss:0.3295,Accuracy：0.9820\n",
      "Epoch:1800,Loss:0.3294,Accuracy：0.9820\n",
      "Epoch:2000,Loss:0.3294,Accuracy：0.9820\n",
      "Epoch:2200,Loss:0.3294,Accuracy：0.9819\n",
      "Epoch:2400,Loss:0.3294,Accuracy：0.9818\n",
      "Epoch:2600,Loss:0.3294,Accuracy：0.9817\n",
      "Epoch:2800,Loss:0.3293,Accuracy：0.9819\n",
      "Epoch:3000,Loss:0.3293,Accuracy：0.9820\n",
      "Epoch:3200,Loss:0.3293,Accuracy：0.9820\n",
      "Epoch:3400,Loss:0.3293,Accuracy：0.9819\n",
      "Epoch:3600,Loss:0.3293,Accuracy：0.9819\n",
      "Epoch:3800,Loss:0.3293,Accuracy：0.9820\n",
      "Epoch:4000,Loss:0.3292,Accuracy：0.9820\n",
      "Epoch:4200,Loss:0.3292,Accuracy：0.9820\n",
      "Epoch:4400,Loss:0.3292,Accuracy：0.9819\n",
      "Epoch:4600,Loss:0.3292,Accuracy：0.9819\n",
      "Epoch:4800,Loss:0.3292,Accuracy：0.9818\n",
      "Epoch:5000,Loss:0.3292,Accuracy：0.9818\n",
      "Epoch:5200,Loss:0.3292,Accuracy：0.9819\n",
      "Epoch:5400,Loss:0.3291,Accuracy：0.9819\n",
      "Epoch:5600,Loss:0.3291,Accuracy：0.9819\n",
      "Epoch:5800,Loss:0.3291,Accuracy：0.9818\n",
      "Epoch:6000,Loss:0.3291,Accuracy：0.9817\n",
      "Epoch:6200,Loss:0.3291,Accuracy：0.9817\n",
      "Epoch:6400,Loss:0.3291,Accuracy：0.9817\n",
      "Epoch:6600,Loss:0.3291,Accuracy：0.9817\n",
      "Epoch:6800,Loss:0.3291,Accuracy：0.9817\n",
      "Epoch:7000,Loss:0.3290,Accuracy：0.9816\n",
      "Epoch:7200,Loss:0.3290,Accuracy：0.9815\n",
      "Epoch:7400,Loss:0.3290,Accuracy：0.9815\n",
      "Epoch:7600,Loss:0.3290,Accuracy：0.9815\n",
      "Epoch:7800,Loss:0.3290,Accuracy：0.9816\n",
      "Epoch:8000,Loss:0.3290,Accuracy：0.9816\n",
      "Epoch:8200,Loss:0.3290,Accuracy：0.9816\n",
      "Epoch:8400,Loss:0.3290,Accuracy：0.9816\n",
      "Epoch:8600,Loss:0.3290,Accuracy：0.9816\n",
      "Epoch:8800,Loss:0.3290,Accuracy：0.9816\n",
      "Epoch:9000,Loss:0.3289,Accuracy：0.9816\n",
      "Epoch:9200,Loss:0.3289,Accuracy：0.9816\n",
      "Epoch:9400,Loss:0.3289,Accuracy：0.9816\n",
      "Epoch:9600,Loss:0.3289,Accuracy：0.9816\n",
      "Epoch:9800,Loss:0.3289,Accuracy：0.9816\n",
      "Epoch:10000,Loss:0.3289,Accuracy：0.9816\n"
     ]
    }
   ],
   "source": [
    "for i in range(epochs):\n",
    "#      指定模型为训练模式，计算梯度\n",
    "    net.train()\n",
    "#      输入值都需要转化成torch的Tensor\n",
    "    x=to_device(torch.from_numpy(train_X.values).float(),device)\n",
    "    y=to_device(torch.from_numpy(train_y.values).long(),device)\n",
    "#     输入数据\n",
    "    y_hat=net(x)\n",
    "#     计算损失\n",
    "    loss=criterion(y_hat,y) \n",
    "#     前一步的损失清零\n",
    "    optm.zero_grad() \n",
    "#     反向传播 \n",
    "    loss.backward() \n",
    "#     更新参数\n",
    "    optm.step() \n",
    "#     writer.add_scalar('tra_loss',loss,i)\n",
    "\n",
    "#     if True:\n",
    "    if (i+1)%200 ==0 : # 这里我们每100次输出相关的信息\n",
    "#         指定模型为计算模式\n",
    "        net.eval()\n",
    "        test_in=to_device(torch.from_numpy(val_X.values).float(),device)\n",
    "        test_l=to_device(torch.from_numpy(val_y.values).long(),device)\n",
    "        test_out=net(test_in)\n",
    "#          使用我们的测试函数计算准确率\n",
    "        accu=test(test_out,test_l)\n",
    "#         writer.add_scalar('tes_loss',loss.item(),i)\n",
    "#         writer.add_scalar('tes_acc',accu,i)\n",
    "        print(\"Epoch:{},Loss:{:.4f},Accuracy：{:.4f}\".format(i+1,loss.item(),accu))    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# writer.close() 97.96%"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 为无标签的数据标上flag"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>zhaiquanrongzi_chengben</th>\n",
       "      <th>zhaiquanrongzi_edu</th>\n",
       "      <th>neiburongzi_and_maoyirongzi_chengben</th>\n",
       "      <th>neiburongzi_and_maoyirongzi_edu</th>\n",
       "      <th>jinglirun</th>\n",
       "      <th>lirunzonge</th>\n",
       "      <th>suoyouzhe_quanyiheji</th>\n",
       "      <th>nashui_zonge</th>\n",
       "      <th>guquanrognzi_chengben</th>\n",
       "      <th>guquanrognzi_edu</th>\n",
       "      <th>yingye_zongshouru</th>\n",
       "      <th>fuzhai_zonge</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1080523.0</th>\n",
       "      <td>0.153910</td>\n",
       "      <td>0.154316</td>\n",
       "      <td>0.334840</td>\n",
       "      <td>0.335179</td>\n",
       "      <td>-0.423658</td>\n",
       "      <td>-0.235871</td>\n",
       "      <td>-0.522061</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>-0.258610</td>\n",
       "      <td>0.416919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1080756.0</th>\n",
       "      <td>2.037227</td>\n",
       "      <td>2.037933</td>\n",
       "      <td>-0.188487</td>\n",
       "      <td>-0.189200</td>\n",
       "      <td>-0.737513</td>\n",
       "      <td>1.150920</td>\n",
       "      <td>-0.921308</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>0.495737</td>\n",
       "      <td>1.237598</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1080951.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>0.396778</td>\n",
       "      <td>0.394059</td>\n",
       "      <td>-0.603652</td>\n",
       "      <td>0.351831</td>\n",
       "      <td>0.076741</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>0.175824</td>\n",
       "      <td>0.557640</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1080972.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.254944</td>\n",
       "      <td>-0.255188</td>\n",
       "      <td>-0.230101</td>\n",
       "      <td>-0.618374</td>\n",
       "      <td>0.206208</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.263837</td>\n",
       "      <td>-0.263875</td>\n",
       "      <td>-0.726563</td>\n",
       "      <td>-0.773093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1081027.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>-0.415439</td>\n",
       "      <td>-0.323241</td>\n",
       "      <td>0.438912</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>0.185092</td>\n",
       "      <td>0.184636</td>\n",
       "      <td>-0.283236</td>\n",
       "      <td>-0.388421</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999614.0</th>\n",
       "      <td>1.952389</td>\n",
       "      <td>1.953307</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>0.250238</td>\n",
       "      <td>0.206426</td>\n",
       "      <td>0.982232</td>\n",
       "      <td>0.157481</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>0.070694</td>\n",
       "      <td>-0.035223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999746.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>0.100278</td>\n",
       "      <td>0.098578</td>\n",
       "      <td>0.038375</td>\n",
       "      <td>-0.239628</td>\n",
       "      <td>-0.104054</td>\n",
       "      <td>0.203587</td>\n",
       "      <td>-0.042700</td>\n",
       "      <td>-0.042990</td>\n",
       "      <td>-0.275084</td>\n",
       "      <td>-0.262263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999945.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.302229</td>\n",
       "      <td>-0.213973</td>\n",
       "      <td>-0.191376</td>\n",
       "      <td>-0.644977</td>\n",
       "      <td>0.255412</td>\n",
       "      <td>-0.449279</td>\n",
       "      <td>-0.276388</td>\n",
       "      <td>-0.276409</td>\n",
       "      <td>-0.761829</td>\n",
       "      <td>-0.810960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999952.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.034825</td>\n",
       "      <td>-0.036087</td>\n",
       "      <td>-0.120922</td>\n",
       "      <td>-0.368322</td>\n",
       "      <td>0.136415</td>\n",
       "      <td>-0.325451</td>\n",
       "      <td>-0.129668</td>\n",
       "      <td>-0.129805</td>\n",
       "      <td>-0.502481</td>\n",
       "      <td>-0.382606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999964.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>0.237081</td>\n",
       "      <td>-0.324532</td>\n",
       "      <td>-0.474946</td>\n",
       "      <td>-0.032688</td>\n",
       "      <td>0.228543</td>\n",
       "      <td>0.229238</td>\n",
       "      <td>-0.408808</td>\n",
       "      <td>0.095954</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10283 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           zhaiquanrongzi_chengben  zhaiquanrongzi_edu  \\\n",
       "ID                                                       \n",
       "1080523.0                 0.153910            0.154316   \n",
       "1080756.0                 2.037227            2.037933   \n",
       "1080951.0                -0.376463           -0.376167   \n",
       "1080972.0                -0.376463           -0.376167   \n",
       "1081027.0                -0.376463           -0.376167   \n",
       "...                            ...                 ...   \n",
       "5999614.0                 1.952389            1.953307   \n",
       "5999746.0                -0.376463           -0.376167   \n",
       "5999945.0                -0.376463           -0.376167   \n",
       "5999952.0                -0.376463           -0.376167   \n",
       "5999964.0                -0.376463           -0.376167   \n",
       "\n",
       "           neiburongzi_and_maoyirongzi_chengben  \\\n",
       "ID                                                \n",
       "1080523.0                              0.334840   \n",
       "1080756.0                             -0.188487   \n",
       "1080951.0                              0.396778   \n",
       "1080972.0                             -0.254944   \n",
       "1081027.0                             -0.325154   \n",
       "...                                         ...   \n",
       "5999614.0                             -0.325154   \n",
       "5999746.0                              0.100278   \n",
       "5999945.0                             -0.302229   \n",
       "5999952.0                             -0.034825   \n",
       "5999964.0                             -0.325154   \n",
       "\n",
       "           neiburongzi_and_maoyirongzi_edu  jinglirun  lirunzonge  \\\n",
       "ID                                                                  \n",
       "1080523.0                         0.335179  -0.423658   -0.235871   \n",
       "1080756.0                        -0.189200  -0.737513    1.150920   \n",
       "1080951.0                         0.394059  -0.603652    0.351831   \n",
       "1080972.0                        -0.255188  -0.230101   -0.618374   \n",
       "1081027.0                        -0.325293  -0.415439   -0.323241   \n",
       "...                                    ...        ...         ...   \n",
       "5999614.0                        -0.325293   0.250238    0.206426   \n",
       "5999746.0                         0.098578   0.038375   -0.239628   \n",
       "5999945.0                        -0.213973  -0.191376   -0.644977   \n",
       "5999952.0                        -0.036087  -0.120922   -0.368322   \n",
       "5999964.0                        -0.325293   0.237081   -0.324532   \n",
       "\n",
       "           suoyouzhe_quanyiheji  nashui_zonge  guquanrognzi_chengben  \\\n",
       "ID                                                                     \n",
       "1080523.0             -0.522061     -0.463019              -0.285456   \n",
       "1080756.0             -0.921308     -0.463019              -0.285456   \n",
       "1080951.0              0.076741     -0.463019              -0.285456   \n",
       "1080972.0              0.206208     -0.463019              -0.263837   \n",
       "1081027.0              0.438912     -0.463019               0.185092   \n",
       "...                         ...           ...                    ...   \n",
       "5999614.0              0.982232      0.157481              -0.285456   \n",
       "5999746.0             -0.104054      0.203587              -0.042700   \n",
       "5999945.0              0.255412     -0.449279              -0.276388   \n",
       "5999952.0              0.136415     -0.325451              -0.129668   \n",
       "5999964.0             -0.474946     -0.032688               0.228543   \n",
       "\n",
       "           guquanrognzi_edu  yingye_zongshouru  fuzhai_zonge  \n",
       "ID                                                            \n",
       "1080523.0         -0.285470          -0.258610      0.416919  \n",
       "1080756.0         -0.285470           0.495737      1.237598  \n",
       "1080951.0         -0.285470           0.175824      0.557640  \n",
       "1080972.0         -0.263875          -0.726563     -0.773093  \n",
       "1081027.0          0.184636          -0.283236     -0.388421  \n",
       "...                     ...                ...           ...  \n",
       "5999614.0         -0.285470           0.070694     -0.035223  \n",
       "5999746.0         -0.042990          -0.275084     -0.262263  \n",
       "5999945.0         -0.276409          -0.761829     -0.810960  \n",
       "5999952.0         -0.129805          -0.502481     -0.382606  \n",
       "5999964.0          0.229238          -0.408808      0.095954  \n",
       "\n",
       "[10283 rows x 12 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "non_label=encoded_all_data.drop(init_x.index)\n",
    "non_label_X=non_label.drop(['flag'],axis=1)\n",
    "estimate_y=estimate_y=np.array([1]*non_label_X.shape[0])\n",
    "non_label_X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " 1,\n",
       " ...]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.eval()\n",
    "test_in=to_device(torch.from_numpy(non_label_X.values).float(),device)\n",
    "test_out=net(test_in)\n",
    "new_label=test_out.max(-1)[1].tolist()\n",
    "new_label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>zhaiquanrongzi_chengben</th>\n",
       "      <th>zhaiquanrongzi_edu</th>\n",
       "      <th>neiburongzi_and_maoyirongzi_chengben</th>\n",
       "      <th>neiburongzi_and_maoyirongzi_edu</th>\n",
       "      <th>jinglirun</th>\n",
       "      <th>lirunzonge</th>\n",
       "      <th>suoyouzhe_quanyiheji</th>\n",
       "      <th>nashui_zonge</th>\n",
       "      <th>guquanrognzi_chengben</th>\n",
       "      <th>guquanrognzi_edu</th>\n",
       "      <th>yingye_zongshouru</th>\n",
       "      <th>fuzhai_zonge</th>\n",
       "      <th>flag</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1080523.0</th>\n",
       "      <td>0.153910</td>\n",
       "      <td>0.154316</td>\n",
       "      <td>0.334840</td>\n",
       "      <td>0.335179</td>\n",
       "      <td>-0.423658</td>\n",
       "      <td>-0.235871</td>\n",
       "      <td>-0.522061</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>-0.258610</td>\n",
       "      <td>0.416919</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1080756.0</th>\n",
       "      <td>2.037227</td>\n",
       "      <td>2.037933</td>\n",
       "      <td>-0.188487</td>\n",
       "      <td>-0.189200</td>\n",
       "      <td>-0.737513</td>\n",
       "      <td>1.150920</td>\n",
       "      <td>-0.921308</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>0.495737</td>\n",
       "      <td>1.237598</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1080951.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>0.396778</td>\n",
       "      <td>0.394059</td>\n",
       "      <td>-0.603652</td>\n",
       "      <td>0.351831</td>\n",
       "      <td>0.076741</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>0.175824</td>\n",
       "      <td>0.557640</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1080972.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.254944</td>\n",
       "      <td>-0.255188</td>\n",
       "      <td>-0.230101</td>\n",
       "      <td>-0.618374</td>\n",
       "      <td>0.206208</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>-0.263837</td>\n",
       "      <td>-0.263875</td>\n",
       "      <td>-0.726563</td>\n",
       "      <td>-0.773093</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1081027.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>-0.415439</td>\n",
       "      <td>-0.323241</td>\n",
       "      <td>0.438912</td>\n",
       "      <td>-0.463019</td>\n",
       "      <td>0.185092</td>\n",
       "      <td>0.184636</td>\n",
       "      <td>-0.283236</td>\n",
       "      <td>-0.388421</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999614.0</th>\n",
       "      <td>1.952389</td>\n",
       "      <td>1.953307</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>0.250238</td>\n",
       "      <td>0.206426</td>\n",
       "      <td>0.982232</td>\n",
       "      <td>0.157481</td>\n",
       "      <td>-0.285456</td>\n",
       "      <td>-0.285470</td>\n",
       "      <td>0.070694</td>\n",
       "      <td>-0.035223</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999746.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>0.100278</td>\n",
       "      <td>0.098578</td>\n",
       "      <td>0.038375</td>\n",
       "      <td>-0.239628</td>\n",
       "      <td>-0.104054</td>\n",
       "      <td>0.203587</td>\n",
       "      <td>-0.042700</td>\n",
       "      <td>-0.042990</td>\n",
       "      <td>-0.275084</td>\n",
       "      <td>-0.262263</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999945.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.302229</td>\n",
       "      <td>-0.213973</td>\n",
       "      <td>-0.191376</td>\n",
       "      <td>-0.644977</td>\n",
       "      <td>0.255412</td>\n",
       "      <td>-0.449279</td>\n",
       "      <td>-0.276388</td>\n",
       "      <td>-0.276409</td>\n",
       "      <td>-0.761829</td>\n",
       "      <td>-0.810960</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999952.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.034825</td>\n",
       "      <td>-0.036087</td>\n",
       "      <td>-0.120922</td>\n",
       "      <td>-0.368322</td>\n",
       "      <td>0.136415</td>\n",
       "      <td>-0.325451</td>\n",
       "      <td>-0.129668</td>\n",
       "      <td>-0.129805</td>\n",
       "      <td>-0.502481</td>\n",
       "      <td>-0.382606</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5999964.0</th>\n",
       "      <td>-0.376463</td>\n",
       "      <td>-0.376167</td>\n",
       "      <td>-0.325154</td>\n",
       "      <td>-0.325293</td>\n",
       "      <td>0.237081</td>\n",
       "      <td>-0.324532</td>\n",
       "      <td>-0.474946</td>\n",
       "      <td>-0.032688</td>\n",
       "      <td>0.228543</td>\n",
       "      <td>0.229238</td>\n",
       "      <td>-0.408808</td>\n",
       "      <td>0.095954</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10283 rows × 13 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           zhaiquanrongzi_chengben  zhaiquanrongzi_edu  \\\n",
       "ID                                                       \n",
       "1080523.0                 0.153910            0.154316   \n",
       "1080756.0                 2.037227            2.037933   \n",
       "1080951.0                -0.376463           -0.376167   \n",
       "1080972.0                -0.376463           -0.376167   \n",
       "1081027.0                -0.376463           -0.376167   \n",
       "...                            ...                 ...   \n",
       "5999614.0                 1.952389            1.953307   \n",
       "5999746.0                -0.376463           -0.376167   \n",
       "5999945.0                -0.376463           -0.376167   \n",
       "5999952.0                -0.376463           -0.376167   \n",
       "5999964.0                -0.376463           -0.376167   \n",
       "\n",
       "           neiburongzi_and_maoyirongzi_chengben  \\\n",
       "ID                                                \n",
       "1080523.0                              0.334840   \n",
       "1080756.0                             -0.188487   \n",
       "1080951.0                              0.396778   \n",
       "1080972.0                             -0.254944   \n",
       "1081027.0                             -0.325154   \n",
       "...                                         ...   \n",
       "5999614.0                             -0.325154   \n",
       "5999746.0                              0.100278   \n",
       "5999945.0                             -0.302229   \n",
       "5999952.0                             -0.034825   \n",
       "5999964.0                             -0.325154   \n",
       "\n",
       "           neiburongzi_and_maoyirongzi_edu  jinglirun  lirunzonge  \\\n",
       "ID                                                                  \n",
       "1080523.0                         0.335179  -0.423658   -0.235871   \n",
       "1080756.0                        -0.189200  -0.737513    1.150920   \n",
       "1080951.0                         0.394059  -0.603652    0.351831   \n",
       "1080972.0                        -0.255188  -0.230101   -0.618374   \n",
       "1081027.0                        -0.325293  -0.415439   -0.323241   \n",
       "...                                    ...        ...         ...   \n",
       "5999614.0                        -0.325293   0.250238    0.206426   \n",
       "5999746.0                         0.098578   0.038375   -0.239628   \n",
       "5999945.0                        -0.213973  -0.191376   -0.644977   \n",
       "5999952.0                        -0.036087  -0.120922   -0.368322   \n",
       "5999964.0                        -0.325293   0.237081   -0.324532   \n",
       "\n",
       "           suoyouzhe_quanyiheji  nashui_zonge  guquanrognzi_chengben  \\\n",
       "ID                                                                     \n",
       "1080523.0             -0.522061     -0.463019              -0.285456   \n",
       "1080756.0             -0.921308     -0.463019              -0.285456   \n",
       "1080951.0              0.076741     -0.463019              -0.285456   \n",
       "1080972.0              0.206208     -0.463019              -0.263837   \n",
       "1081027.0              0.438912     -0.463019               0.185092   \n",
       "...                         ...           ...                    ...   \n",
       "5999614.0              0.982232      0.157481              -0.285456   \n",
       "5999746.0             -0.104054      0.203587              -0.042700   \n",
       "5999945.0              0.255412     -0.449279              -0.276388   \n",
       "5999952.0              0.136415     -0.325451              -0.129668   \n",
       "5999964.0             -0.474946     -0.032688               0.228543   \n",
       "\n",
       "           guquanrognzi_edu  yingye_zongshouru  fuzhai_zonge  flag  \n",
       "ID                                                                  \n",
       "1080523.0         -0.285470          -0.258610      0.416919     1  \n",
       "1080756.0         -0.285470           0.495737      1.237598     1  \n",
       "1080951.0         -0.285470           0.175824      0.557640     1  \n",
       "1080972.0         -0.263875          -0.726563     -0.773093     1  \n",
       "1081027.0          0.184636          -0.283236     -0.388421     1  \n",
       "...                     ...                ...           ...   ...  \n",
       "5999614.0         -0.285470           0.070694     -0.035223     0  \n",
       "5999746.0         -0.042990          -0.275084     -0.262263     0  \n",
       "5999945.0         -0.276409          -0.761829     -0.810960     0  \n",
       "5999952.0         -0.129805          -0.502481     -0.382606     0  \n",
       "5999964.0          0.229238          -0.408808      0.095954     0  \n",
       "\n",
       "[10283 rows x 13 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "non_label_X['flag']=new_label\n",
    "non_label_X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Float64Index: 45931 entries, 28.0 to 5999999.0\n",
      "Data columns (total 13 columns):\n",
      "flag                                    45931 non-null float64\n",
      "fuzhai_zonge                            45931 non-null float64\n",
      "guquanrognzi_chengben                   45931 non-null float64\n",
      "guquanrognzi_edu                        45931 non-null float64\n",
      "jinglirun                               45931 non-null float64\n",
      "lirunzonge                              45931 non-null float64\n",
      "nashui_zonge                            45931 non-null float64\n",
      "neiburongzi_and_maoyirongzi_chengben    45931 non-null float64\n",
      "neiburongzi_and_maoyirongzi_edu         45931 non-null float64\n",
      "suoyouzhe_quanyiheji                    45931 non-null float64\n",
      "yingye_zongshouru                       45931 non-null float64\n",
      "zhaiquanrongzi_chengben                 45931 non-null float64\n",
      "zhaiquanrongzi_edu                      45931 non-null float64\n",
      "dtypes: float64(13)\n",
      "memory usage: 4.9 MB\n"
     ]
    }
   ],
   "source": [
    "logistic_final=encoded_all_data.combine_first(non_label_X)\n",
    "logistic_final.info()\n",
    "logistic_final.to_csv(r'./data/created_data/logistic_final.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8933821f171e4caba63d45d1c2a4c1d2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Tab(children=(HTML(value='<div id=\"overview-content\" class=\"row variable spacing\">\\n    <div class=\"row\">\\n   …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "Report generated with <a href=\"https://github.com/pandas-profiling/pandas-profiling\">pandas-profiling</a>."
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ppf.ProfileReport(logistic_final)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
